<template>
    <div class="nest">
        <el-form class="search-form" inline size="mini">
            <el-form-item>
                <el-input v-model="search.username" placeholder="输入用户名称" clearable @change="getList" />
            </el-form-item>
            <el-form-item>
                <el-input v-model="search.referee_id" placeholder="推荐人id" clearable @change="getList" />
            </el-form-item>
            <!-- <el-form-item>
                <el-input v-model="search.username" placeholder="输入会员等级" clearable @change="getList" />
            </el-form-item> -->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">查询</el-button>
                <el-button icon="el-icon-refresh-left" size="mini" @click="handleResetSearch">重置</el-button>
            </el-form-item>
            <Recharge ref="Recharge" @success="getList"></Recharge>
        </el-form>
        <div class="table">
            <el-table :data="tableData" style="width: 100%;margin-bottom: 20px;" v-loading="loading">
                <el-table-column prop="id" label="ID" width="130" show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="头像" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-image :src="scope.row.avatar" :preview-src-list="[scope.row.avatar]" style="width: 60px" />
                    </template>
                </el-table-column>
                <el-table-column prop="nickname" label="用户名称" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="phone" label="手机号" show-overflow-tooltip>
                </el-table-column>
                <!-- <el-table-column prop="v4" label="累计消费" show-overflow-tooltip>
                </el-table-column> -->
                <el-table-column prop="money" label="剩余余额" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="auth_type" label="用户来源" show-overflow-tooltip>
                    <template slot-scope="{row}">
                        <span v-if="row.auth_type == 1">抖音小程序</span>
                        <span v-else-if="row.auth_type == 2">微信小程序</span>
                        <span v-else-if="row.auth_type == 3">快手小程序</span>
                        <span v-else-if="row.auth_type == 4">H5网页</span>
                    </template>
                </el-table-column>
                <el-table-column prop="created_at" label="创建时间" show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini"
                            @click="$refs.Recharge.handleEdit(scope.row)">充值</el-button>
                        <el-button size="mini" @click="queryDetailed(scope.row)">明细</el-button>
                        <el-button type="primary" size="mini" @click="queryWorks(scope.row)">作品</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div style="text-align: right;">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="search.page" :page-sizes="[10, 20, 30, 40, 100]" :page-size="search.size" background
                    layout="total, sizes, prev, pager, next" :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import Recharge from "./recharge.vue"

export default {
    components: { Recharge },
    data() {
        return {
            loading: false,
            search: {
                username: "",	//true	string		昵称
                referee_id: "",	//true	string		推荐人id
                page: 1,	//true	int		当前页
                size: 10,	//true	int		每页多少条
            },
            tableData: [],
            total: 0,
        }
    },
    created() {
        this.getList()
    },
    methods: {
        queryDetailed(data) {
            this.$router.push({ name: 'list-detailed', query: { user_id: data.id } })
        },
        queryWorks(data){
            // console.log(data);
            this.$router.push({ name: 'product', query: { user_id: data.id } })
        },
        // 用户列表
        async getList() {
            this.loading = true
            let res = await this.$request({
                url: '/admin/user.user/index',
                method: 'get',
                params: this.search
            })
            this.loading = false
            if (res.code == 200) {
                this.tableData = res.result.data
                this.total = res.result.total
            }
        },
        handleResetSearch() {
            this.search = {
                username: "",	//true	string		昵称
                referee_id: "",	//true	string		手机号
            }
            this.getList()
        },
        //分页
        handleSizeChange(e) {
            this.search.size = e;
            this.getList()
        },
        handleCurrentChange(e) {
            this.search.page = e;
            this.getList()
        },
    }
}
</script>

<style lang="scss">
.nest {
    width: 100%;
    height: 60px;

    .search-form {
        background: #fff;
        border-radius: 12px;
        padding: 12px 20px;
        margin-bottom: 20px;

        .el-form-item--mini.el-form-item {
            margin-bottom: 0;
        }
    }

    .table {
        padding: 12px 20px;
        background: #fff;

        .el-table__body-wrapper {
            max-height: calc(100vh - 300px);
            overflow-y: auto;
        }
    }
}
</style>
